cmake_minimum_required(VERSION 3.8)
project(map_manager)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

add_definitions(-DROOT_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/\") 

find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(PCL REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(pcl_conversions REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(OpenCV REQUIRED)

add_executable(demo_load_pcl src/demo_load_pcl.cpp)
add_executable(build_2d_map src/build_2d_map.cpp)
add_executable(load_2d_map src/load_2d_map.cpp)
add_executable(publish_2d_map src/publish_2d_map.cpp)

# Add include directories for PCL
target_include_directories(demo_load_pcl PRIVATE ${PCL_INCLUDE_DIRS})
target_include_directories(build_2d_map PRIVATE
  ${PCL_INCLUDE_DIRS}
  ${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_include_directories(load_2d_map PRIVATE
  ${PCL_INCLUDE_DIRS}
  ${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_include_directories(publish_2d_map PRIVATE
  ${PCL_INCLUDE_DIRS}
  ${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(demo_load_pcl ${PCL_LIBRARIES})
target_link_libraries(build_2d_map ${OpenCV_LIBS} ${PCL_LIBRARIES})
target_link_libraries(load_2d_map ${OpenCV_LIBS} ${PCL_LIBRARIES})
target_link_libraries(publish_2d_map ${OpenCV_LIBS} ${PCL_LIBRARIES})

# ament_target_dependencies is equivalent to include_directories and target_link_libraries
# Only supporting official pkgs
ament_target_dependencies(demo_load_pcl rclcpp sensor_msgs pcl_conversions)
ament_target_dependencies(build_2d_map rclcpp sensor_msgs pcl_conversions nav_msgs)
ament_target_dependencies(load_2d_map rclcpp sensor_msgs pcl_conversions nav_msgs)
ament_target_dependencies(publish_2d_map rclcpp sensor_msgs pcl_conversions nav_msgs)

# -------- INSTALL ---------- #
install(TARGETS demo_load_pcl build_2d_map load_2d_map publish_2d_map
  DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY launch DESTINATION share/${PROJECT_NAME})
install(DIRECTORY config DESTINATION share/${PROJECT_NAME})

ament_package()
